#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<sys/types.h>

char* const addenv[] = {
    (char* const)"MYVAL=12345",
    (char* const)"Eemo=happy",
    (char* const)"What=hhhhh",
    NULL
};

int main()
{
    printf("我的进程要开始执行了!\n");
    //execl("./wait","wait",NULL);
    //execl("/usr/bin/top","top",NULL);
   //execl("/usr/bin/ls","ls","-a","-l",NULL);


    
    //execlp("top","top",NULL);
    //execlp("ls","ls","-a","-l",NULL);
    //

    pid_t id = fork();
    if(id==0)
    {
        //child
        printf("我是一个子进程，my id is %d\n",getpid());
        sleep(1);

        char* const argv[]={
            (char* const)"ls",
            (char* const)"-a",
            (char* const)"-l",
            
            NULL
        };

        extern char **environ;
        for(int i = 0;addenv[i];i++)
        {
            putenv(addenv[i]);
        }

        execle("/usr/bin/env","env",NULL,environ);
        //execvp("ls",argv);
        //execv("/usr/bin/ls",argv);

        printf("hello zxy!\n");

        exit(1);
    }

    waitpid(-1,NULL,0);
    printf("进程执行完毕!\n");
    return 0;
}
